home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Comms & Internet / LinkConverter 1.1.2 / Dialog Director v0.7 / Examples / Set Folder Windows.as < prev    next >
Encoding:
Text File  |  1998-01-18  |  6.4 KB  |  171 lines  |  [TEXT/ToyS]

  1. -- These properties set the vertical & horizontal offsets to use for each
  2. -- sucessive level of windows.
  3. property pVerticalOffset : 15 -- how much to offset the windows down for each level
  4. property pHorizontalOffset : 0 -- how much to offset the windows right for each level
  5. property pStaggerBottoms : false
  6.  
  7. -- These properties set the top and bottom of the first window of the item dropped on the script.
  8. -- The difference of these two values defines the height of all windows.
  9. property pWindTopStart : 40 -- the top of the drive window
  10. property pWindBotStart : 650 -- the bottom of the first winow
  11.  
  12. -- These properties set the left and right of the first window of the item dropped on the script.
  13. -- The difference of these two values defines the width of all windows.
  14. property pWindLeftStart : 2
  15. property pWindRightStart : 380
  16.  
  17. -- a list of properties for setting the view of a window
  18. property pViewSettingList : ¬
  19.     {pBySmallIcon:0, pByIcon:1, pByName:2, pBySize:4 ¬
  20.         , pByKind:5, pByLabel:7, pByLastModified:3, pByVersion:8, pByComment:6}
  21. property pViewSettingMenu : [0, 1, 2, 4, 5, 7, 3, 8, 6]
  22.  
  23. -- This property controls the type of view you want ALL windows to have
  24. property pViewType : pByName of pViewSettingList
  25.  
  26. (******************************)
  27.  
  28. on run
  29.     set theItem to choose folder with prompt "Locate disk to process."
  30.     open {theItem} -- as a list
  31. end run
  32.  
  33. (******************************)
  34.  
  35. on open theItems -- the Finder always provides us with a list, even for a single item
  36.     set viewItem to 1
  37.     repeat with i from 1 to pViewSettingMenu's length
  38.         if pViewSettingMenu's item i = pViewType then
  39.             set viewItem to i
  40.             exit repeat
  41.         end if
  42.     end repeat
  43.     
  44.     set dSetFolderWindows to {size:[310, 280], name:"Set Folder Windows", style:movable dialog, contents:[¬
  45.         {class:push button, bounds:[240, 250, 300, 270], name:"OK"}, ¬
  46.         {class:push button, bounds:[165, 250, 225, 270], name:"Cancel"}, ¬
  47.         {class:text field, bounds:[98, 40, 148, 56], value:pWindLeftStart}, ¬
  48.         {class:text field, bounds:[237, 40, 287, 56], value:pWindTopStart}, ¬
  49.         {class:text field, bounds:[98, 66, 148, 82], value:pWindBotStart}, ¬
  50.         {class:text field, bounds:[237, 66, 287, 82], value:pWindRightStart}, ¬
  51.         {class:static text, bounds:[20, 40, 90, 56], contents:"Left"}, ¬
  52.         {class:static text, bounds:[176, 40, 233, 56], contents:"Top"}, ¬
  53.         {class:static text, bounds:[20, 66, 90, 82], contents:"Bottom"}, ¬
  54.         {class:static text, bounds:[176, 66, 233, 82], contents:"Right"}, ¬
  55.         {class:group box, bounds:[10, 10, 300, 98], name:"First Window"}, ¬
  56.         {class:text field, bounds:[98, 140, 148, 156], value:pHorizontalOffset}, ¬
  57.         {class:text field, bounds:[237, 140, 287, 156], value:pVerticalOffset}, ¬
  58.         {class:static text, bounds:[20, 140, 90, 156], contents:"Horizontal"}, ¬
  59.         {class:static text, bounds:[176, 140, 233, 156], contents:"Vertical"}, ¬
  60.         {class:group box, bounds:[10, 110, 300, 200], name:"Windows Offset"}, ¬
  61.         {class:check box, bounds:[20, 173, 180, 191], name:"Stagger Bottoms", value:pStaggerBottoms}, ¬
  62.         {class:pop up, bounds:[10, 210, 190, 230], name:"View", value:viewItem, contents:["by Small Icon", "by Icon", "by Name", "by Size", "by Size", "by Kind", "by Label", "by Last Modified", "by Version", "by Comment"]} ¬
  63.             ] ¬
  64.         }
  65.     
  66.     set dVals to dd auto dialog dSetFolderWindows with grayscale
  67.     set [_, cancel, pWindLeftStart, pWindTopStart, pWindBotStart, pWindRightStart, _, _, _, _, _ ¬
  68.         , pHorizontalOffset, pVerticalOffset, _, _, _, pStaggerBottoms, viewItem, _] to dVals
  69.     if cancel then return
  70.     set pViewType to pViewSettingMenu's item viewItem
  71.     
  72.     set startTime to time of (current date)
  73.     
  74.     repeat with anItem in theItems
  75.         tell application "Finder" to set itemKind to kind of anItem
  76.         if itemKind is in {"folder", "disk"} then
  77.             HProcessContainer for contents of anItem
  78.         end if
  79.     end repeat
  80.     
  81.     set endTime to time of (current date)
  82.     display dialog "Execution time: " & (endTime - startTime)
  83. end open
  84.  
  85. (******************************)
  86.  
  87. on HProcessContainer for theContainer
  88.     set folderDepth to 0
  89.     
  90.     set windowBounds to HCalculateWindowBounds for folderDepth
  91.     
  92.     ignoring application responses
  93.         tell application "Finder"
  94.             open theContainer -- we've got to open the window before we can set it's values
  95.             
  96.             set bounds of window of theContainer to windowBounds
  97.             set view of window of theContainer to pViewType
  98.             
  99.             -- ensures that if the windows are set to a list view, nested folders are not open
  100.             if pViewType is greater than 1 then
  101.                 set expanded of folders of theContainer to false
  102.             end if
  103.             
  104.             close theContainer -- done with the window, close it
  105.         end tell
  106.     end ignoring
  107.     
  108.     HProcessContainedFolders for theContainer at folderDepth
  109. end HProcessContainer
  110.  
  111. (******************************)
  112.  
  113. on HProcessContainedFolders for theContainer at folderDepth
  114.     set folderDepth to folderDepth + 1
  115.     set windowBounds to HCalculateWindowBounds for folderDepth
  116.     
  117.     -- process all the folder inside this container as a group for speed        
  118.     -- since Finder operation return a list of the objects they operated on, we can save an call here
  119.     tell application "Finder" to set folderList to open folders in theContainer
  120.     
  121.     if (count of folderList) > 0 then
  122.         tell application "Finder"
  123.             ignoring application responses
  124.                 set bounds of window of folders in theContainer to windowBounds
  125.                 set view of window of folders in theContainer to pViewType
  126.                 
  127.                 -- ensure that if the windows are set to a list view, nested folders are not open
  128.                 if pViewType > 1 then
  129.                     set expanded of folders of window of folders in theContainer to false
  130.                 end if
  131.                 
  132.                 close windows -- folders in theContainer
  133.             end ignoring
  134.         end tell
  135.         
  136.         repeat with aFolder in folderList
  137.             HProcessContainedFolders for aFolder at folderDepth
  138.         end repeat
  139.     end if
  140. end HProcessContainedFolders
  141.  
  142. (******************************)
  143.  
  144. to HCalculateWindowBounds for folderDepth
  145.     -- Calculate the values to be used for window bounds
  146.     if pVerticalOffset = 0 then
  147.         set windTop to pWindTopStart
  148.         set windBot to pWindBotStart
  149.     else
  150.         set vertOffset to folderDepth * pVerticalOffset
  151.         set windTop to pWindTopStart + vertOffset
  152.         
  153.         if pStaggerBottoms then
  154.             set windBot to pWindBotStart + vertOffset
  155.         else
  156.             set windBot to pWindBotStart
  157.         end if
  158.     end if
  159.     
  160.     if pHorizontalOffset = 0 then
  161.         set windLeft to pWindLeftStart
  162.         set windRight to pWindRightStart
  163.     else
  164.         set horizOffset to folderDepth * pHorizontalOffset
  165.         set windLeft to pWindLeftStart + horizOffset
  166.         set windRight to pWindRightStart + horizOffset
  167.     end if
  168.     
  169.     return {windLeft, windTop, windRight, windBot}
  170. end HCalculateWindowBounds
  171.